//-----------------------------------------------------------------------------
// After Effects - Vertex Shader
//-----------------------------------------------------------------------------
#include "AfterEffectCommon.hlsl"

#if AFTER_EFFECT_ID == AE_TYPE_BLOOM_DOWNSAMPLE
// ------------------------------------------------------------------------------------------------
// BLOOM EFFECT - STEP 1 (DOWNSAMPLE)
// ------------------------------------------------------------------------------------------------
uniform float4 g_vScreenResolution;		// x ->width y->height z->0.5/width w->0.5/height 

    VSOUT ProcessVertex( VSIN _input )
    {
        VSOUT Output = (VSOUT)0;
        Output.Position.xy = _input.Position.xy;
        Output.Position.z  = 0.0f;
        Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
        TexCoord.x = TexCoord.x + g_vScreenResolution.z;
        TexCoord.y = 1.0 - TexCoord.y + g_vScreenResolution.w;

		float2 texelSize = DOWNSAMPLE_SCALE / g_vScreenResolution.xy;
		float2 s = TexCoord.xy;

		Output.TexCoord0.xy = s;
		Output.TexCoord1.xy = s + float2(2, 0) * texelSize;
		Output.TexCoord2.xy = s + float2(2, 2) * texelSize;
		Output.TexCoord3.xy = s + float2(0, 2) * texelSize;

		return Output;
	}

#elif AFTER_EFFECT_ID == AE_TYPE_BLOOM_BLUR
// ------------------------------------------------------------------------------------------------
// BLOOM EFFECT - STEP 2 (BLUR H Dir / V Dir)
// ------------------------------------------------------------------------------------------------
uniform float4 g_vScreenResolution;		// x ->width y->height z->0.5/width w->0.5/height 
uniform float4 g_vBlurDirection;
uniform float4 g_fBlurWidth;

    VSOUT ProcessVertex( VSIN _input )
    {
        VSOUT Output = (VSOUT)0;
        Output.Position.xy = _input.Position.xy;
        Output.Position.z  = 0.0f;
        Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
        TexCoord.x = TexCoord.x + g_vScreenResolution.z;
        TexCoord.y = 1.0 - TexCoord.y + g_vScreenResolution.w;

		float2 texelSize = g_fBlurWidth.x / g_vScreenResolution.xy;
		float2 s = TexCoord.xy - texelSize * (7 - 1) * 0.5 * g_vBlurDirection.xy;

		Output.TexCoord0.xy = s;
		Output.TexCoord1.xy = s + texelSize * 1 * g_vBlurDirection.xy;
		Output.TexCoord2.xy = s + texelSize * 2 * g_vBlurDirection.xy;
		Output.TexCoord3.xy = s + texelSize * 3 * g_vBlurDirection.xy;
		Output.TexCoord4.xy = s + texelSize * 4 * g_vBlurDirection.xy;
		Output.TexCoord5.xy = s + texelSize * 5 * g_vBlurDirection.xy;
		Output.TexCoord6.xy = s + texelSize * 6 * g_vBlurDirection.xy;
		Output.TexCoord7.xy = s + texelSize * 7 * g_vBlurDirection.xy;

		return Output;
	}

#elif AFTER_EFFECT_ID == AE_TYPE_BLOOM_COMBINE
// ------------------------------------------------------------------------------------------------
// BLOOM EFFECT - STEP 3 (Combine to final buffer)
// ------------------------------------------------------------------------------------------------
uniform float4 g_vScreenResolution;		// x ->width y->height z->0.5/width w->0.5/height 

	VSOUT ProcessVertex( VSIN _input )
    {
        VSOUT Output = (VSOUT)0;
        Output.Position.xy = _input.Position.xy;
        Output.Position.z  = 0.0f;
        Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
        TexCoord.y = 1.0 - TexCoord.y;

		Output.TexCoord0.xy = TexCoord.xy + g_vScreenResolution.zw;
		Output.TexCoord1.xy = TexCoord.xy + (g_vScreenResolution.zw / DOWNSAMPLE_SCALE);

        return Output;
    }

#elif AFTER_EFFECT_ID == AE_TYPE_FOG_LAYERED || AFTER_EFFECT_ID == AE_TYPE_FOG_LINEAR
// ------------------------------------------------------------------------------------------------
// POST PROCESS FOG EFFECT - ( Height layered / LINEAR Fog )
// ------------------------------------------------------------------------------------------------
uniform float4 g_vScreenResolution;		// x ->width y->height z->0.5/width w->0.5/height 

	VSOUT ProcessVertex( VSIN _input )
    {
        VSOUT Output = (VSOUT)0;
        Output.Position.xy = _input.Position.xy;
        Output.Position.z  = 0.0f;
        Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
        TexCoord.y = 1.0 - TexCoord.y;

		Output.TexCoord0.xy = TexCoord.xy + g_vScreenResolution.zw;
		Output.TexCoord0.zw = _input.Position.xy;

        return Output;
    }
    
#elif AFTER_EFFECT_ID == AE_TYPE_DOF
// ------------------------------------------------------------------------------------------------
// POST PROCESS Depth Of Field ( FullScreen DOF )
// ------------------------------------------------------------------------------------------------
	
	VSOUT ProcessVertex( VSIN _input )
	{
		VSOUT Output = (VSOUT)0;
		Output.Position.xy = _input.Position.xy;
		Output.Position.z  = 0.0f;
		Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
		TexCoord.y = 1.0 - TexCoord.y;

		Output.TexCoord0.xy = TexCoord.xy;

		return Output;
	}
		
#elif AFTER_EFFECT_ID == AE_TYPE_FXAA
// ------------------------------------------------------------------------------------------------
// POST PROCESS FXAA ( FullScreen Anti-Alias)
// ------------------------------------------------------------------------------------------------
uniform float4 g_vScreenResolution;		// x ->width y->height z->1/width w->1/height 

	VSOUT ProcessVertex( VSIN _input )
    {
		#define FXAA_SUBPIX_SHIFT (0.0f/4.0f)

        VSOUT Output = (VSOUT)0;
        Output.Position.xy = _input.Position.xy;
        Output.Position.z  = 0.0f;
        Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
        TexCoord.y = 1.0 - TexCoord.y;

		Output.TexCoord0.xy = TexCoord.xy /*+ g_vScreenResolution.zw * 0.5f*/;
		Output.TexCoord0.zw = Output.TexCoord0.xy - (g_vScreenResolution.zw * (0.5f + FXAA_SUBPIX_SHIFT));

        return Output;
    }

#elif AFTER_EFFECT_ID == AE_TYPE_HeadLight
// ------------------------------------------------------------------------------------------------
// POST PROCESS HeadLight ( FullScreen Black Circle Ring )
// ------------------------------------------------------------------------------------------------
uniform float4 g_vScreenResolution;		// x ->width y->height z->1/width w->1/height 
uniform float4 g_vCircleCenter;			// Circle center in world space
uniform float4 g_vTexcoordScale;		// Circle texture Texcoord scale

	VSOUT ProcessVertex( VSIN _input )
    {
        VSOUT Output = (VSOUT)0;
        Output.Position.xy = _input.Position.xy;
        Output.Position.z  = 0.0f;
        Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
        TexCoord.y = 1.0 - TexCoord.y;

		Output.TexCoord0.xy = TexCoord.xy + g_vScreenResolution.zw;
		Output.TexCoord0.z = 0;
		Output.TexCoord0.w = 0;		
		
		float4 TexCoord2;
		TexCoord2.xy = 0.5f * (_input.Position.xy * g_vTexcoordScale.x + 1.0f) ;
        TexCoord2.y = 1.0 - TexCoord2.y;
        
        		
		float4 TexCoord3 = mul(g_vCircleCenter, g_mWorldViewProj);
		TexCoord3.xy = TexCoord3.xy / TexCoord3.w;
		TexCoord3.xy = clamp(TexCoord3.xy, 0, 1);
		TexCoord3.xy = 0.5f * (TexCoord3.xy + 1.0f) ;
        TexCoord3.y = 1.0 - TexCoord3.y;
		
		float2 TexCoordOffset = float2(0.5f, 0.5f) - TexCoord3.xy;
		    
		Output.TexCoord1.xy = TexCoord2.xy + TexCoordOffset;
		Output.TexCoord1.zw = Output.TexCoord0.zw;
		
		
        return Output;
    }

#elif AFTER_EFFECT_ID == AE_TYPE_Gamma
// ------------------------------------------------------------------------------------------------
// POST PROCESS Gamma Correction
// ------------------------------------------------------------------------------------------------

uniform float4 g_vScreenResolution;		// x ->width y->height z->0.5/width w->0.5/height 
	
	VSOUT ProcessVertex( VSIN _input )
    {
        VSOUT Output = (VSOUT)0;
        Output.Position.xy = _input.Position.xy;
        Output.Position.z  = 0.0f;
        Output.Position.w  = 1.0f;

		float4 TexCoord;
		TexCoord.xy = 0.5f * (_input.Position.xy + 1.0f) ;
        TexCoord.y = 1.0 - TexCoord.y;

		Output.TexCoord0.xy = TexCoord.xy + g_vScreenResolution.zw;

        return Output;
    }

#else
// ------------------------------------------------------------------------------------------------
// DEFAULT
// ------------------------------------------------------------------------------------------------
    VSOUT ProcessVertex( VSIN _input )
    {
        VSOUT Output = (VSOUT)0;

        return Output;
    }

#endif
